#ifndef _DRV_PACKER_H_
#define _DRV_PACKER_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
//使用动态内存
#define USE_DYNAMIC_MEM 0
//最长消息长度
#define MAX_PACK_SIZE 65530 //100k

//数据包头
#define STX_L 0X55
typedef struct
{
    //动态内存
#if !USE_DYNAMIC_MEM
	uint8_t packer[MAX_PACK_SIZE + 5]  ; //用来做payload序列化的内存
#else
    uint8_t *packer; //用来做payload序列化的内存
#endif
    //cmd长度
    uint16_t flen;

    //cmd 校验计算值
    uint8_t test;

    //cmd 校验位
    uint8_t check;

    //cmd 消息类型
    uint8_t type;

    //cmd 解析状态
    uint8_t state;

    //cmd数据接收cnt
    uint16_t cnt;

    //数据包处理回调
    uint8_t (*cb)(uint8_t type, uint8_t *data, uint16_t len);

    //数据发送回调
    void (*send)(uint8_t *data, uint16_t size);
} CMD_Packer;

void DRV_PackerInit(CMD_Packer *cmd_packer, uint8_t (*handler)(uint8_t type, uint8_t *data, uint16_t len), void (*send)(uint8_t *data, uint16_t size));
void DRV_Unpack(CMD_Packer *packer, uint8_t *buff, uint16_t size);
void DRV_Pack(CMD_Packer *packer, uint8_t *buff, uint16_t size, uint8_t type);


#endif
